<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function admin_login(){
        $a = M('admin');
        $username = I('post.username');
        $password = I('post.password');
        $data = $a->create();
        $sql = "username= '{$data['username']}' and password='{$data['password']}'";
        $arr = $a->where($sql)->find();
//       if($arr){
//           session('user_id',$arr['id']);
//           $this->success('登录成功',U());
//           $this->display();
//      }else{
//           $this->error('用户名或者密码错误');
//       }
    }
    //超级管理员登录页面

    public function register(){
        $u = D('user');
        $data = $u->create();
//        var_dump($data);
        if($data){
            $password = I('post.password');
            $password2 = I('post.password');
            if($password==$password2){
                $data['password'] = md5($data['password']);
                $u->add($data);
                $this->success('注册成功',U('user_login'));
            }else{
                $u->getError();
            }
        }
        $this->display();
    }
    //用户注册页面

    public function user_login(){
        $u = M('user');
        $data = $u->create();
//        var_dump($data);
        $data['password'] = md5($data['password']);
        $arr = $u->where($data)->find();
//        var_dump($arr);
        if($arr){
            session('user_id',$arr['id']);
            $this->success('登录成功');
        }
        $this->display();
    }
    //用户登录

    public function index(){
        $this->display();
    }
    public  function details(){
        $this->display();
    }
    public function pay(){
        $this->display();
    }
}
